package br.ufpe.cin.imlm2.jbeat.soot.common;

import java.util.ArrayList;
import java.util.List;

import br.ufpe.cin.imlm2.util.options.Option;
import br.ufpe.cin.imlm2.util.options.Options;
import br.ufpe.cin.imlm2.util.options.Option.OptionBuilder;

public class CommonOptions extends Options {

	public static final String ANALYZE_LIBRARIES = "analyzeLibs";
	public static final String VERBOSE = "verbose";

	public static final String FILTERS = "filters";
	public static final String FILTER_UNCHECKED = "unchecked";
	public static final String FILTER_CHECKED = "checked";
	public static final String FILTER_APPLICATION = "application";
	public static final String FILTER_LIBRARY = "library";
	public static final String EXCEPTION_INTERFACES_ONLY = "interfacesOnly";

	public CommonOptions() {
		super();
		this.addOption( new Option( ANALYZE_LIBRARIES, "libs",
				"Tells whether LIBRARY classes should be included"
						+ " in the analysis or not.", Boolean.FALSE ) );
		this.addOption( new Option( VERBOSE, "v", "Verbose output during analysis.", Boolean.FALSE ) );
		this.addOption( new Option( "enabled", null,
				"Confirms whether or not this Transformer is enabled", Boolean.TRUE, Boolean.class, null ) );
		Option option = new OptionBuilder( FILTERS, new ArrayList<String>(), List.class,
				String.class ).build();
		String defValues = "'" + FILTER_APPLICATION + "', " + "'" + FILTER_CHECKED + "', " + "'"
				+ FILTER_LIBRARY + "' and " + "'" + FILTER_UNCHECKED + "'";
		option.setDescription( "A list of exception filters. Exceptions will be filtered out"
				+ " during propagation/instruction inspection depending on the listed filters. Possible values are any "
				+ "combination of " + defValues + " or any fully qualified class name that is "
				+ "subclass of java.lang.Throwable ." );
		this.options.add( option );
		this.addOption( new Option( EXCEPTION_INTERFACES_ONLY, null, "Defines if only "
				+ "the exception interfaces from methods in LIBRARY classes should "
				+ "be considered during the analysis.", Boolean.TRUE ) );
	}

	public boolean isAnalyzeLibraries() {
		return (Boolean) this.getOptionInternal( ANALYZE_LIBRARIES ).getValue();
	}

	public boolean isVerbose() {
		return (Boolean) this.getOptionInternal( VERBOSE ).getValue();
	}

	@SuppressWarnings("unchecked")
	public List<String> getFilters() {
		return (List<String>) this.getOptionInternal( FILTERS ).getValue();
	}

	public boolean isExceptionInterfacesOnly() {
		return (Boolean) this.getOptionInternal( EXCEPTION_INTERFACES_ONLY ).getValue();
	}
}
